;
export class Play {

	hlsPlayer;
	flvPlayer;
	video;
	constructor({
		videoDom
	}) {
		this.video = videoDom;
	}

	isHlsFlv(url) {
		var extension = url.substring(url.lastIndexOf('.') + 1);

		if ("m3u8" == extension.toLowerCase()) {
			return "hls";
		}
		if ("flv" == extension.toLowerCase()) {
			return "flv";
		}
		return "";
	}

	hPlay(url) {
		//this.hStop();
		if ('hls' == this.isHlsFlv(url)) {
			let hlsPlayer = new Hls();
			hlsPlayer.loadSource(url);
			hlsPlayer.attachMedia(this.video);
			hlsPlayer.on(Hls.Events.MANIFEST_PARSED, () => {
				this.video.play();
			});
			this.hlsPlayer = hlsPlayer;

		} else if ('flv' == this.isHlsFlv(url)) {
			let flvPlayer = flvjs.createPlayer({
				type: 'flv',
				url: url
			});
			flvPlayer.attachMediaElement(this.video);
			flvPlayer.load();
			flvPlayer.play();
			this.flvPlayer = flvPlayer;
		} else {
			console.log("错误类型地址")
		}
	}

	hStop() {
		if (typeof this.hlsPlayer !== "undefined") {
			if (this.hlsPlayer != null) {
				this.hlsPlayer.destroy();
			}
		}
		if (typeof this.flvPlayer !== "undefined") {
			if (this.flvPlayer != null) {
				this.flvPlayer.unload();
				this.flvPlayer.detachMediaElement();
				this.flvPlayer.destroy();
				this.flvPlayer = null;
			}
		}
		this.onStop();
	};
	onStop() {}
}